package com.loubobooo.personal.blog.controller.portal;

import com.loubobooo.personal.blog.entity.vo.*;
import com.loubobooo.personal.blog.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller public class PageController {
    @Autowired private PageService pageService;

    @Autowired private ArticleService articleService;

    @Autowired private CategoryService categoryService;

    @Autowired private TagService tagService;

    //页面显示
    @RequestMapping(value = "/{key}")
    public ModelAndView ArticleDetailView(@PathVariable("key") String key) {
        ModelAndView modelAndView = new ModelAndView();
        PageVO pageVO = pageService.getPageByKey(1, key);
        if (pageVO != null) {
            modelAndView.addObject("pageVO", pageVO);
            modelAndView.setViewName("Home/Page/page");
        }
        else {
            modelAndView.setViewName("Home/Error/404");
        }
        return modelAndView;
    }

    //文章归档页面显示
    @RequestMapping(value = "/articleFile")
    public ModelAndView articleFile() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("Home/Page/articleFile");
        List<ArticleListVo> articleList = articleService.listArticle(1);
        modelAndView.addObject("articleList", articleList);
        return modelAndView;
    }

    //站点地图显示
    @RequestMapping(value = "/map")
    public ModelAndView siteMap() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("Home/Page/siteMap");
        //文章显示
        List<ArticleListVo> articleList = articleService.listArticle(1);
        modelAndView.addObject("articleList", articleList);
        //分类显示
        List<CategoryVO> categoryVOList = categoryService.listCategory(1);
        modelAndView.addObject("categoryVOList", categoryVOList);
        //标签显示
        List<TagVO> tagVOList = tagService.listTag(1);
        modelAndView.addObject("tagVOList", tagVOList);

        return modelAndView;
    }

    //留言板
    @RequestMapping(value = "/message") public ModelAndView message() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("Home/Page/message");
        return modelAndView;
    }
}
